/***************************************************************************//**
 * @file MSc_Vector3.cpp
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/
#ifndef MSC_VECTOR3_CPP
#define MSC_VECTOR3_CPP
#endif

////////////////////////////////////////////////////////////////////////////////

#include <cmath>

#include <utils/MSc_Vector3.h>

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3::MSc_Vector3() :
    MSc_Vector<3>(),

    m_x ( m_items[ 0 ] ),
    m_y ( m_items[ 1 ] ),
    m_z ( m_items[ 2 ] )
{}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3::MSc_Vector3( const MSc_Vector3 &vect ) :
    MSc_Vector<3>(),

    m_x ( m_items[ 0 ] ),
    m_y ( m_items[ 1 ] ),
    m_z ( m_items[ 2 ] )
{
    m_x = vect.m_x;
    m_y = vect.m_y;
    m_z = vect.m_z;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::getFrom( double x, double y, double z )
{
    MSc_Vector3 result;

    result.set( x, y, z );

    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::getFrom( const double items[] )
{
    MSc_Vector3 result;

    result.setArray( items );

    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::getNormalized() const
{
    MSc_Vector3 result( *this );

    result.normalize();

    return result;
}

////////////////////////////////////////////////////////////////////////////////

void MSc_Vector3::set( double x, double y, double z )
{
    m_x = x;
    m_y = y;
    m_z = z;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3& MSc_Vector3::operator= ( const MSc_Vector3 &vect )
{
    m_x = vect.m_x;
    m_y = vect.m_y;
    m_z = vect.m_z;
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::operator+ ( const MSc_Vector3 &vect ) const
{
    MSc_Vector3 result;
    
    result.m_x = m_x + vect.m_x;
    result.m_y = m_y + vect.m_y;
    result.m_z = m_z + vect.m_z;
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::operator- () const
{
    MSc_Vector3 result;
    
    result.m_x = -m_x;
    result.m_y = -m_y;
    result.m_z = -m_z;
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::operator- ( const MSc_Vector3 &vect ) const
{
    MSc_Vector3 result;
    
    result.m_x = m_x - vect.m_x;
    result.m_y = m_y - vect.m_y;
    result.m_z = m_z - vect.m_z;
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::operator* ( double val ) const
{
    MSc_Vector3 result;
    
    result.m_x = m_x * val;
    result.m_y = m_y * val;
    result.m_z = m_z * val;
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::operator/ ( double val ) const
{
    MSc_Vector3 result;
    
    result.m_x = m_x / val;
    result.m_y = m_y / val;
    result.m_z = m_z / val;
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3 MSc_Vector3::operator% ( const MSc_Vector3 &vect ) const
{
    MSc_Vector3 result;
    
    result.m_x = m_y * vect.m_z - m_z * vect.m_y;
    result.m_y = m_z * vect.m_x - m_x * vect.m_z;
    result.m_z = m_x * vect.m_y - m_y * vect.m_x;
    
    return result;
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3& MSc_Vector3::operator+= ( const MSc_Vector3 &vect )
{
    m_x += vect.m_x;
    m_y += vect.m_y;
    m_z += vect.m_z;
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3& MSc_Vector3::operator-= ( const MSc_Vector3 &vect )
{
    m_x -= vect.m_x;
    m_y -= vect.m_y;
    m_z -= vect.m_z;
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3& MSc_Vector3::operator*= ( double val )
{
    m_x *= val;
    m_y *= val;
    m_z *= val;
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3& MSc_Vector3::operator/= ( double val )
{
    m_x /= val;
    m_y /= val;
    m_z /= val;
    
    return (*this);
}

////////////////////////////////////////////////////////////////////////////////

MSc_Vector3& MSc_Vector3::operator%= ( const MSc_Vector3 &vect )
{
    (*this) = (*this) % vect;
    
    return (*this);
}
